import { useEffect, useState } from "react"
import {getChannels}  from "@/apis/article.js"
//自定义获取频道列表的hooks
const useChannels=()=>{ 
    //频道列表数据
    const [channels,setChannels] = useState([])
    //发起异步请求获取频道列表数据
    async function fetchChannels(){
        const res=await getChannels()
        console.log("频道数据",res);
        setChannels(res.data.channels)
    }
    useEffect(()=>{//渲染完成时渲染
        fetchChannels()
    },[])
    
    //返回状态数据
    return {
        channels
    }
}

//按需导出hooks函数
export {useChannels}
